package com.cmict.data.system.api.permission;

import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.framework.common.util.collection.CollectionUtils;
import com.cmict.data.system.api.permission.dto.RoleDTO;
import com.cmict.data.system.api.user.dto.AdminUserRespDTO;
import com.cmict.data.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@FeignClient(name = ApiConstants.NAME) // TODO awesome：fallbackFactory =
@Api(tags = "RPC 服务 - 角色")
public interface RoleApi {

    String PREFIX = ApiConstants.PREFIX + "/role";

    @GetMapping(PREFIX + "/valid")
    @ApiOperation("校验角色是否合法")
    @ApiImplicitParam(name = "ids", value = "角色编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<Boolean> validRoles(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/roles-by-ids-join")
    @ApiOperation("获取角色")
    @ApiImplicitParam(name = "ids", value = "角色编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<List<RoleDTO>> getRolesByIdsJoin(@RequestParam("ids") String ids);
    default Map<Long, RoleDTO> getRoleMap(Collection<Long> ids) {
        String idList = StringUtils.join(ids, ",");
        return CollectionUtils.convertMap(getRolesByIdsJoin(idList).getCheckedData(), RoleDTO::getId);
    }
    @GetMapping(PREFIX + "/roles")
    @ApiOperation("获取角色")
    @ApiImplicitParam(name = "ids", value = "角色编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<List<RoleDTO>> getRoles(@RequestParam("ids") Collection<Long> ids);

}
